package andy.demo.parseXML.sax.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import andy.demo.parseXML.sax.domain.Person;


public class SAXService {
	
	public static ArrayList<Person> readXML (InputStream in) {
//		ArrayList<Person> personList = new ArrayList<Person>();
		
		try {
			
			SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
			SAXParser saxParser = saxParserFactory.newSAXParser();
			
			XmlContentHandler xmlContentHandler = new XmlContentHandler();
			
			saxParser.parse(in, xmlContentHandler);
			
			in.close();
			
			return  xmlContentHandler.getPersonList();
		
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
		
	}
	
}
